from flask import Flask,render_template,redirect,url_for,request
from api.pdf_bulider import pdf_print
from flask_bootstrap import Bootstrap
from models.MyForm import MyForm
from api.erp_db import Select_MB001

app = Flask(__name__)
app.config['SECRET_KEY'] = '12345678'
Bootstrap(app)


@app.route('/')
def hello_world():
    form = MyForm()
    return render_template('home.html',form=form)

@app.route('/print',methods=['POST'])
def print():
    form = MyForm()
    if form.is_submitted():
        data_print = (
            {'MB001':form.MB001.data,'single_num': form.single_num.data, 'total_num': form.total_num.data, 'print_count': form.print_count.data,'billNo':form.BillNo.data},
        )
        pdf_print(data_print)

        return redirect(url_for('static',filename='print.pdf'))
    return '没有数据'

@app.route('/bill_info',methods=['GET'])
def bill_info():
    bill_no = request.args.get('bill_no')
    return str(Select_MB001(bill_no))


@app.route('/test')
def test():
    return render_template('test.html')












if __name__ == '__main__':



    app.run()



